﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NineSeas.Extensions
{
    public static class MessageDefinitions
    {
        public static class Types
        {
            public static readonly string Error = "error";
            public static readonly string Info = "info";
            public static readonly string Warning = "warning";
        }

        // empty message
        public static readonly MessageDefinition NORMAL = new MessageDefinition { Code = 0, Type = Types.Info };
        public static readonly MessageDefinition UNKNOWN = new MessageDefinition { Code = 1, Type = Types.Error, Message = "Unknown Error" };

        // general book - related errors        
        public static readonly MessageDefinition INSUFFICIENT_PRIVILEDGE =                  new MessageDefinition { Code = 600, Type = Types.Error, Message = "Insufficient priviledge" };
        public static readonly MessageDefinition BOOK_CANNOT_EDIT_OTHERS =                  new MessageDefinition { Code = 601, Type = Types.Error, Message = "Cannot edit others' books" };
        public static readonly MessageDefinition BOOK_NAME_REQUIRED =                       new MessageDefinition { Code = 602, Type = Types.Error, Message = "Name of the book is required" };
        public static readonly MessageDefinition BOOK_NAME_CONTAINS_SPECIAL_CHARS =         new MessageDefinition { Code = 603, Type = Types.Error, Message = "Name contains special characters" };
        public static readonly MessageDefinition BOOK_NAMEONURL_REQUIRED =                  new MessageDefinition { Code = 604, Type = Types.Error, Message = "NameOnUrl of the book is required" };
        public static readonly MessageDefinition BOOK_NAMEONURL_NOT_UNIQUE =                new MessageDefinition { Code = 605, Type = Types.Error, Message = "NameOnUrl not unique" };
        public static readonly MessageDefinition BOOK_NAMEONURL_CONTAINS_SPECIAL_CHARS =    new MessageDefinition { Code = 606, Type = Types.Error, Message = "NameOnUrl  contains special characters" };
        public static readonly MessageDefinition BOOK_INTRODUCTION_REQUIRED =               new MessageDefinition { Code = 607, Type = Types.Error, Message = "Introduction is required" };
        public static readonly MessageDefinition BOOK_INTRODUCTION_TOO_LONG =               new MessageDefinition { Code = 608, Type = Types.Error, Message = "Introduction is too long" };
        public static readonly MessageDefinition BOOK_CATEGORY_REQUIRED =                   new MessageDefinition { Code = 609, Type = Types.Error, Message = "Category is required" };
        public static readonly MessageDefinition BOOK_COVER_REQUIRED =                      new MessageDefinition { Code = 610, Type = Types.Error, Message = "Cover Image is required" };

        // book publishing errors
        public static readonly MessageDefinition BOOK_PUBLISHING_INVALID_DATETIME =         new MessageDefinition { Code = 620, Type = Types.Error, Message = "Invalid Date and/or Time value" };
        public static readonly MessageDefinition BOOK_PUBLISHING_DATE_IN_PAST =             new MessageDefinition { Code = 621, Type = Types.Error, Message = "Date in the past" };
        public static readonly MessageDefinition BOOK_PUBLISHING_DATETIME_REQUIRED =        new MessageDefinition { Code = 622, Type = Types.Error, Message = "Both Date and Time are required" };

        // tags
        public static readonly MessageDefinition TAGS_FORBIDDEN_CHARS =                     new MessageDefinition { Code = 630, Type = Types.Warning, Message = "Contains forbidden chars" };

        // media
        public static readonly MessageDefinition MEDIA_NO_FILE =                            new MessageDefinition { Code = 640, Type = Types.Error, Message = "No file provided" };
        public static readonly MessageDefinition MEDIA_FILE_INCORRECT_FORMAT =              new MessageDefinition { Code = 641, Type = Types.Error, Message = "File not in a correct format" };

        public static readonly MessageDefinition SIGNIN_USERNAME_REQUIRED =                 new MessageDefinition { Code = 700, Type = Types.Error, Message = "You must specify a username or e-mail." };
        public static readonly MessageDefinition SIGNIN_PASSWORD_REQUIRED =                 new MessageDefinition { Code = 701, Type = Types.Error, Message = "You must specify a password." };
        public static readonly MessageDefinition SIGNIN_FAILED =                            new MessageDefinition { Code = 702, Type = Types.Error, Message = "The username or e-mail or password provided is incorrect." }; 

        static MessageDefinitions()
        {
            All = new List<MessageDefinition> {
                NORMAL,
                UNKNOWN,

                INSUFFICIENT_PRIVILEDGE,
                BOOK_CANNOT_EDIT_OTHERS,
                BOOK_NAME_REQUIRED,
                BOOK_NAME_CONTAINS_SPECIAL_CHARS,
                BOOK_NAMEONURL_REQUIRED,
                BOOK_NAMEONURL_NOT_UNIQUE,
                BOOK_NAMEONURL_CONTAINS_SPECIAL_CHARS,
                BOOK_INTRODUCTION_REQUIRED,
                BOOK_INTRODUCTION_TOO_LONG,
                BOOK_CATEGORY_REQUIRED,
                BOOK_COVER_REQUIRED,

                BOOK_PUBLISHING_INVALID_DATETIME,
                BOOK_PUBLISHING_DATE_IN_PAST,
                BOOK_PUBLISHING_DATETIME_REQUIRED,

                TAGS_FORBIDDEN_CHARS,
         
                MEDIA_NO_FILE,
                MEDIA_FILE_INCORRECT_FORMAT,
                
                SIGNIN_USERNAME_REQUIRED,
                SIGNIN_PASSWORD_REQUIRED,
                SIGNIN_FAILED
            }.ToDictionary(m => m.Code);
        }
        
        public static IDictionary<int, MessageDefinition> All { get; private set; }
    }

    
    public class MessageDefinition
    {
        public int Code { get; set; }
        public string Type { get; set; }
        public string Message { get; set; }
        public string Description { get; set; }
    }
}